package cn.darkhorse.common.util;

import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.sql.SqlUtil;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @description:
 * @author: mr.wang
 * @time: 2023/10/18 9:20
 */
public class SysUserTranslation {
	
	Map<Long,String> sysUserMap = new HashMap<>();
	
	
	public SysUserTranslation() {
		String sql = "select  user_id as userId,nick_name as nickName from sys_user";
		List<Map<String, Object>> userList = SqlRunner.db().selectList(sql);
		Map<Long,String> userMap = userList.stream().collect(Collectors.toMap(each-> Long.valueOf(each.get("userId").toString()), each->Objects.toString(each.get("nickName"),""),(key1, key2)->key1));
		this.sysUserMap = userMap;
	}
	
	/**
	 * 人员翻译
	 * @param userIds
	 */
	public String personnelTranslation(String userIds){
		StringBuilder personNames= new StringBuilder();
		if(StringUtils.isNotBlank(userIds)){
			String[] users = userIds.split(",");
			for(String us:users){
				String nickName = sysUserMap.get(Long.valueOf(us));
				if(null!= nickName){
					personNames.append(nickName);
					personNames.append(",");
				}
			}
		}
		return StringUtils.isBlank(personNames.toString())?"":personNames.toString().substring(0,personNames.toString().lastIndexOf(","));
	}
	
	
	
	
	
}
